package com.link2room.soundwave.controller.manager;

import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import com.link2room.soundwave.dto.param.manager.L2RPMSCouponManagerParamDto;
import com.link2room.soundwave.dto.result.base.L2RPmsCouponDto;
import com.link2room.soundwave.facade.IL2RPMSCouponFacadeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import static com.link2room.soundwave.constant.PermissionConstant.*;

/**
 * @author sqj88
 * @date 2018/1/4 17:14
 */
@Api(tags = "联房-PMS电子券")
@RestController
@RequestMapping("/manager/L2RPMSCoupons")
public class L2RPMSCouponManagerController {
    @Resource
    private IL2RPMSCouponFacadeService l2RPMSCouponFacadeService;


    @ApiOperation(value ="获取联房PMS电子券列表")
    @ApiImplicitParam(name = "l2RCouponType", value = "联房电子券类型", required = false, dataType = "String")
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = L2RPMSCouponList,name = "获取联房PMS电子券列表")
    public BaseResultDto<L2RPmsCouponDto> listL2RPMSCouponList(
            @RequestParam(value = "l2RCouponType", required = false) String l2RCouponType
    ) throws Exception{
        L2RPMSCouponManagerParamDto l2RPMSCouponManagerParamDto=new L2RPMSCouponManagerParamDto();
        l2RPMSCouponManagerParamDto.setL2RCouponType(l2RCouponType);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(l2RPMSCouponFacadeService.listL2RPMSCoupons(l2RPMSCouponManagerParamDto));
        return  baseResultDto;
    }

    @ApiOperation(value ="检查电子券代码")
    @ApiImplicitParam(name = "pmsCouponCode", value = "PMS电子券代码", required = true, dataType = "String")
    @RequestMapping(value = "/PmsCouponCode",method = RequestMethod.GET)
    public BaseResultDto<L2RPmsCouponDto> checkPmsCouponCode(
            @RequestParam(value = "pmsCouponCode") String pmsCouponCode
    ) throws Exception{
        L2RPMSCouponManagerParamDto l2RPMSCouponManagerParamDto=new L2RPMSCouponManagerParamDto();
        l2RPMSCouponManagerParamDto.setPmsCouponCode(pmsCouponCode);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        l2RPMSCouponFacadeService.checkPmsCouponCode(l2RPMSCouponManagerParamDto);
        return  baseResultDto;
    }

    @ApiOperation(value ="获取联房PMS电子券")
    @ApiImplicitParam(name="id",value="电子券id对照",dataType="Long", paramType = "path",example="12")
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @L2RPermissionResources(value = L2RPMSCoupon,name = "获取联房PMS电子券")
    public BaseResultDto<L2RPmsCouponDto> getL2RPMSCoupon(
            @PathVariable Long id
    ) throws Exception{
        BaseL2rParamDto baseL2rParamDto=new BaseL2rParamDto();
        baseL2rParamDto.setId(id);
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(l2RPMSCouponFacadeService.getL2RPMSCoupon(baseL2rParamDto));
        return  baseResultDto;
    }

    @ApiOperation(value ="保存联房PMS电子券")
    @RequestMapping(method = RequestMethod.POST)
    @L2RPermissionResources(value = newL2RPMSCoupon,name = "保存联房PMS电子券")
    public BaseResultDto<L2RPmsCouponDto> saveL2RPMSCoupon(
            @RequestBody L2RPMSCouponManagerParamDto l2RPMSCouponManagerParamDto
    ) throws Exception{
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(l2RPMSCouponFacadeService.saveL2RPMSCoupon(l2RPMSCouponManagerParamDto));
        return  baseResultDto;
    }

    @ApiOperation(value ="更新联房PMS电子券")
    @RequestMapping(method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateL2RPMSCoupon,name = "更新联房PMS电子券")
    public BaseResultDto<L2RPmsCouponDto> updateL2RPMSCoupon(
            @RequestBody L2RPMSCouponManagerParamDto l2RPMSCouponManagerParamDto
    ) throws Exception{
        BaseResultDto baseResultDto = new BaseResultDto();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(l2RPMSCouponFacadeService.updateL2RPMSCoupon(l2RPMSCouponManagerParamDto));
        return  baseResultDto;
    }
}
